package com.allianz.webapps.controllers;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.allianz.webapps.https.interfaces.type001.pojo.User;
import com.allianz.webapps.https.interfaces.type005.Type005PkgGetHotList;
import com.allianz.webapps.https.interfaces.type005.pojo.PkgGetHot;
import com.allianz.webapps.https.interfaces.util.HttpsUtil;
import com.allianz.webapps.https.interfaces.util.ObjectUtil;
//http://localhost:8080/pad_marketing/main/type005pkgGetHotList.action
@Controller
@RequestMapping(value="main")
public class Type005PkgGetHotListController {
	
	@Autowired
	private Type005PkgGetHotList type005PkgGetHotList;
	@Autowired
	private ObjectUtil objectUtil;
	@RequestMapping(value="type005pkgGetHotList")
	@ResponseBody
	public Map<String,String> pkgGetHot(HttpServletRequest request,HttpServletResponse response) throws Exception{
		HttpSession hs = request.getSession();
		User u = (User)hs.getAttribute("username");
		String body1 = objectUtil.requestParam(u, "pkg.getHotList");
		JSONObject json=new JSONObject(body1);
		Map<String,String> bodyMap=new HashMap<String, String>();
		if(json.get("Body").equals(null)){
			bodyMap.put("pkgGetHotList", "");
			return bodyMap;
		}else{
			String body=json.getString("Body");
			JSONArray json1 = JSONArray.fromObject(body);
			if (json1.size() > 1) {
				bodyMap.put("pkgGetHotList", body);
				return bodyMap;
			} else {
				body = body.replace("[{", "{");
				body = body.replace("}]", "}");
				bodyMap.put("pkgGetHotList", body);
				return bodyMap;
			}
		}
		
	}
	//http://localhost:8080/pad_marketing/main/type005pkgGetHot.action
	@RequestMapping(value="type005pkgGetHot")
	public ModelAndView redirect(HttpServletRequest request,HttpServletResponse response){
		return new ModelAndView("views/page/listViewHot");
	}
}